﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OnWork.Tools.Swagger;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace SwaggerTest.Controllers
{
    /// <summary>
    /// 天气
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    [ApiExplorerSettingsOnWork("Group1", "Group2",Order =1)]
    public class Group2Controller : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IConfiguration Configuration;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="logger"></param>
        public Group2Controller(ILogger<WeatherForecastController> logger, IConfiguration configuration)
        {
            _logger = logger;
            Configuration = configuration;
        }

        /// <summary>
        /// 获取天气信息 "Group1", "Group2"
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }


        /// <summary>
        /// 获取参数读取测试
        /// </summary>
        /// <returns></returns>
        [HttpGet("SettingTest")]
        public object GetSettingTest([FromQuery]ModelVM modelVM)
        {
            var Options = Configuration.GetSection(SwaggerSettingsOptions.SwaggerSettings)
                                                     .Get<SwaggerSettingsOptions>();

            return Options;

        }
    }

    /// <summary>
    /// 模型对象
    /// </summary>
    public class ModelVM
    {

        /// <summary>
        /// 名称
        /// </summary>
        [DefaultValue("陈超")]
        public string Name { get; set; } = "Chen";
        /// <summary>
        /// 性别
        /// </summary>
        public string Sex { get; set; }


    } 
}
